function a(t) {
    wx.request({
        url: getApp().globalData.host + "/lotto/v1/vip",
        data: {
            access_token: n.getStorage("accessToken")
        },
        method: "GET",
        success: function(e) {
            if (-500 != e.data.sta) {
                if (0 == e.data.sta) {
                    var o = n.getStorage("userInfo");
                    t.setData({
                        showDev: e.data.data,
                        avatar: o.avatarUrl,
                        nickname: o.nickName
                    });
                }
            } else n.login(function() {
                a(t);
            });
        }
    });
}

function t(a) {
    wx.request({
        url: getApp().globalData.host + "/lotto/v1/client_stat",
        data: {
            access_token: n.getStorage("accessToken")
        },
        method: "GET",
        success: function(e) {
            -500 != e.data.sta ? 0 == e.data.sta && (a.setData({
                counts: e.data.data
            }), a.setData({
                contactUserInfo: '{ "nickName": "' + n.getStorage("userInfo").nickName + '", "avatarUrl": "' + n.getStorage("userInfo").avatarUrl + '" }'
            })) : n.login(function() {
                t(a), a.setData({
                    hasUserInfo: !0
                });
            }, function() {
                a.setData({
                    hasUserInfo: !1
                });
            });
        },
        fail: function(a) {
            n.showModelTips("数据加载失败，" + a.errMsg);
        }
    });
}

function e(a) {
    n.showLoading("正在保存数据");
    var t = a.data.phone, o = a.data.code;
    o = o ? parseInt(o) : "", o = 1 == a.data.isDev ? 9999999 : o;
    var i = {
        access_token: wx.getStorageSync("accessToken"),
        subscribe: a.data.subscribe
    };
    t != a.data.oldPhone && (i.phone = t), wx.request({
        url: s.globalData.host + "/lotto/v1/client_info",
        data: i,
        method: "POST",
        success: function(t) {
            n.hideLoading(), -500 != t.data.sta ? 0 != t.data.sta ? (n.showFailedToast("设置失败", t.data.msg), 
            a.setData({
                subscribe: !a.data.subscribe
            })) : a.data.subscribe ? n.showModelTips("上新抽奖会发通知提醒。", "订阅成功") : n.showToast("您已经取消订阅") : n.login(function() {
                e(a);
            });
        },
        fail: function(a) {
            n.hideLoading(), n.showFailedToast("数据保存失败");
        }
    });
}

var o = Object.assign || function(a) {
    for (var t = 1; t < arguments.length; t++) {
        var e = arguments[t];
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (a[o] = e[o]);
    }
    return a;
}, n = require("../../utils/util.js"), i = require("../../tmp/tmp.js"), s = getApp();

Page({
    data: {
        avatar: "",
        nickname: "",
        subscribe: !1,
        noticeBoard: s.globalData.noticeBoard,
        showDev: !1,
        contactUserInfo: '{ "nickName": "' + n.getStorage("userInfo").nickName + '", "avatarUrl": "' + n.getStorage("userInfo").avatarUrl + '" }'
    },
    onLoad: function(a) {
        wx.canIUse && this.setData({
            canContact: wx.canIUse("button.open-type.contact"),
            canShare: wx.canIUse("button.open-type.share")
        });
        var e = wx.getSystemInfoSync().SDKVersion;
        this.setData({
            SDKVersion: e
        }), i.noticeBoard(this);
        var o = this;
        i.wxLogin(this, function() {
            var a = wx.getStorageSync("userInfo");
            o.setData({
                avatar: a.avatarUrl,
                nickname: a.nickName
            }), t(o);
        });
    },
    onShow: function() {
        var e = this;
        n.checkSession(this, function() {
            var o = wx.getStorageSync("userInfo");
            e.setData({
                avatar: o.avatarUrl,
                nickname: o.nickName
            }), t(e), a(e);
        });
    },
    shareWx: function() {
        n.showModelTips('点击右上角三个点"..."，转发到群里或转发给好友吧~');
    },
    openNoticeBoard: function() {
        var a = this.data.SDKVersion;
        if (n.compareVersion(a, "1.6.4") > 0) wx.navigateTo({
            url: "/pages/webview/webview?url=https://mp.weixin.qq.com/s/JXFboIdFffH6Rb3Y6PEHsw"
        }); else {
            var t = this.data.noticeBoard;
            t.showUpgradeDialog = 1, this.setData({
                noticeBoard: t
            });
        }
    },
    longtap: function() {
        if (this.data.unionid) {
            var a = this.data.unionid;
            wx.setClipboardData({
                data: a,
                success: function(t) {
                    n.showModelTips("unionid复制成功：" + a);
                }
            });
        } else loadUnionid(this, !0);
    },
    myCreate: function() {
        n.buttonClicked(this), wx.navigateTo({
            url: "/pages/mycreate/mycreate"
        });
    },
    myJoin: function() {
        n.buttonClicked(this), wx.navigateTo({
            url: "/pages/myjoin/myjoin"
        });
    },
    myPrize: function() {
        n.buttonClicked(this), wx.navigateTo({
            url: "/pages/myprize/myprize"
        });
    },
    postFormId: function(a) {
        n.postFormId(a.detail.formId);
    },
    toRecommend: function() {
        n.buttonClicked(this), wx.navigateTo({
            url: "/pages/recommend/recommend"
        });
    },
    toDev: function() {
        n.buttonClicked(this), wx.navigateTo({
            url: "../dev/dev"
        });
    },
    clientInfo: function() {
        n.buttonClicked(this), wx.navigateTo({
            url: "/pages/userinfo/userinfo?is_dev=" + this.data.showDev
        });
    },
    getUserInfo: function(a) {
        if (this.data.longtap) this.setData({
            longtap: !1
        }); else {
            var t = this;
            n.showLoading("正在获取用户信息..."), n.buttonLogin(function() {
                n.hideLoading();
            }, function() {
                n.hideLoading();
            }, a.detail);
            var e = a.detail.userInfo;
            e && t.setData({
                avatar: e.avatarUrl,
                nickname: e.nickName
            });
        }
    },
    onShareAppMessage: function() {
        return o({
            title: "每日精选福利，海量奖品免费拿"
        }, {
            imageUrl: "https://cdn-xcxcustom.weiyoubot.cn/20180727/8f738700913ab760b2028b17eee32392.jpg"
        }, {
            path: "/pages/dailylotto/dailylotto"
        });
    },
    changeSubscrible: function(a) {
        console.log(a), this.setData({
            subscribe: a.detail.value
        }), e(this);
    }
});